<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <style>
        img {
            width: 100px;
        }
    </style> -->
</head>

<body>
    <!-- <img src="../images/good/s.gif" alt=""> -->
    <script>
        // /*//根据当前时间，在网页上显示对应的图片
        //                         0:00~8:00:早上好
        //                         9；00~12:00:上午好
        //                         13:00~18:00:下午好
        //                         19:00~23:00:晚上好*/
        // var img = document.querySelector('img');
        // var time = new Date();
        // var h = time.getHours();
        // if (h <= 8) {
        //     img.src = '';
        // } else if (h <= 12) {
        //     img.src = 's.gif';
        // } else if (h <= 18) {
        //     img.src = 'x.gif';
        // } else if (h <= 23) {
        //     img.src = 'w.jif';
        // }




        var inputYear = window.prompt("请输入年：");
        var inputMonth = window.prompt("请输入月：") - 1;
        var newDate = new Date(inputYear, inputMonth, 1);
        var week = newDate.getDay();//得到星期几
        var howManyDay = new Date(inputYear, inputMonth + 1, 0).getDate();
        var lastDays = new Date(inputYear, inputMonth, 0).getDate();
        document.write("<div>" + inputYear + "年" + (inputMonth + 1) + "月" + "</div>");
        document.write("<div>日	一	二	三	四	五	六</div>");
        var calendar = "";
        for (var i = lastDays - week + 1; i <= lastDays; i++) {//打印空格
            calendar += '<span style="color:gray">' + i + "</span>" + "	"
        }
        document.write(calendar);
        var nums = "";
        for (var i = 1; i <= howManyDay; i++) {//打印日历
            /* if(i==date){
               nums+=i+'<span style="color:red;vertical-align: top;">'+'*</span>'+"	";
             }else {*/
            nums += i + "	";
            // }
            if ((i + week) % 7 == 0) {
                nums += "<br>";
            }

        }
        document.write(nums);
        var kong = "";
        var lastKong = 7 - (howManyDay + week) % 7;
        if (lastKong != 0) {
            for (var i = 1; i <= lastKong; i++) {
                kong += '<span style="color:gray">' + i + "</span>" + "	"
            }
            document.write(kong);
        }

    </script>
</body>

<ml>